// JavaScript Document
/*
//mobile_rnd
var mobilefie = G("mobile_Field");
var mobilefieDiv=mobilefie.getElementsByTagName("div")[1];
var mobileatt=mobilefie.getElementsByTagName("p")[0];
var mobileerr=mobilefie.getElementsByTagName("p")[1];
var mobileok=mobilefie.getElementsByTagName("p")[2];
var namemobile = G("mobile_rnd");
namemobile.onfocus=function()
{
	if(namemobile.value == "请输入您收到的短信验证码"){
		namemobile.value = "";
	} else {
		namemobile.select();
	}
	addClass(mobilefie,"hover");
	if(namemobile.value == ""){
		mobilefieDiv.style.display="block";
		mobileatt.style.display="block";
		mobileerr.style.display="none";
		namemobile.className = "U_Field";
		return;
	}
}

namemobile.onblur=function(){
	mobilefie.className="field";
	if(namemobile.value == ""){
		mobileatt.style.display="none";
		mobileerr.style.display="none";
		mobileok.style.display="none";
		namemobile.className="input_other";
		namemobile.value = "请输入您收到的短信验证码";
		return;
	}
	//if (!NameField()) {
	//	return;
	//}
	//检测是否存在账号
	//if (!NameExit()) {
	//	return;
	//}
}
//
*/var UserFie=G("UserNameField");
var UserFieDiv=UserFie.getElementsByTagName("div")[1];
var Useratt=UserFie.getElementsByTagName("p")[0];
var Usererror=UserFie.getElementsByTagName("p")[1];
var Userok=UserFie.getElementsByTagName("p")[2];
var UserId=G("U_UserName");
var nameFlag = true;
UserId.onfocus=function(){
	if(UserId.value == "请输入您的手机号码"){
		UserId.value = "";
	} else {
		UserId.select();
	}
	addClass(UserFie,"hover");
	if(UserId.value == ""){
		UserFieDiv.style.display="block";
		Useratt.style.display="block";
		Usererror.style.display="none";
		UserId.className = "U_Field";
		return;
	}
}
UserId.onblur=function(){
	UserFie.className="field";
	if(UserId.value == ""){
		Useratt.style.display="none";
		Usererror.style.display="none";
		Userok.style.display="none";
		UserId.className="input_other";
		UserId.value = "请输入您的手机号码";
		return;
	}
	if (!NameField()) {
		return;
	}
	//检测是否存在账号
	if (!NameExit()) {
		return;
	}
}

function NameField(){
	var errtext1="您填写的手机号码有误,请确认后输入";
	var str = UserId.value;
	var patn =  /^1[3|4|5|8|7][0-9]\d{8}$/;
	if(patn.test(str)){
		if(checkByteLength(str,5,30)){
			//Reg.checkName(obj.value,callback_chkUserName);
			Usererror.style.display="none";
			Useratt.style.display="none";
			Userok.style.display="block";
			UserId.className="U_Field";
			return true;
		}
	}
	UserFieDiv.style.display="block";		
	Usererror.style.display="block";
	Useratt.style.display="none";
	Userok.style.display="none";
	Usererror.innerHTML=errtext1;
	addClass(UserId,"error");
	return false;
}

function checkByteLength(str,minlen,maxlen) {
	if (str == null) return false;
	var l = str.length;
	var blen = 0;
	for(i=0; i<l; i++) {
		if ((str.charCodeAt(i) & 0xff00) != 0) {
			blen ++;
		}
		blen ++;
	}
	if (blen > maxlen || blen < minlen) {
		return false;
	}
	return true;
}
function NameExit() {
	//验证手机是否注册
	//return Pwd2.checkName(UserId.value, callbackName);
	$.post(
			'/interface/valiphone/',
			'userphone='+UserId.value,	
			function(data){
				
				if (data.result == false)
					{
					UserFieDiv.style.display="block";		
					Usererror.style.display="block";
					Useratt.style.display="none";
					Userok.style.display="none";
					Usererror.innerHTML=data.message;
					addClass(UserId,"error");
					UserId.focus();
					return false;
					}
			},
			'json'
	);
}

function callbackName(flag) {
	nameFlag = flag;
	var errtext2="Email已被注册";
	if (!flag) {
		UserFieDiv.style.display="block";		
		Usererror.style.display="block";
		Useratt.style.display="none";
		Userok.style.display="none";
		Usererror.innerHTML=errtext2;
		addClass(UserId,"error");
		return false;
	}
	Usererror.style.display="none";
	Useratt.style.display="none";
	Userok.style.display="block";
	UserId.className="U_Field";
	return true;
}

var CodeFieId=G("U_CodeField");
var CodeId=G("U_Code");
var CodeDiv=CodeFieId.getElementsByTagName("div")[1];
var Codeatt=CodeFieId.getElementsByTagName("p")[0];
var Codeerror=CodeFieId.getElementsByTagName("p")[1];
var Codeok=CodeFieId.getElementsByTagName("p")[2];
CodeId.onfocus=function(){
	addClass(CodeFieId,"hover");
	if(CodeId.value==""){
		CodeDiv.style.display="block";
		Codeatt.style.display="block";
		Codeerror.style.display="none";
		CodeId.className="U_Field";
	}
	if (document.getElementById("U_CheckCode").style.display == "none") {
		nchangeImg();
	}
}
CodeId.onblur=function(){
	if(CodeId.value==""){		
		CodeDiv.style.display="none";
		Codeatt.style.display="none";
		CodeId.className="U_Field";
		CodeFieId.className="field code-field";
		return false;	
	}
    CodeField();
}
function CodeField(){
	if(CodeId.value == '' || CodeId.value.length != 4){
		CodeDiv.style.display="block";		
		Codeerror.style.display="block";
		Codeatt.style.display="none";
		Codeok.style.display="none";
		Codeerror.innerHTML="请输入4位验证码";
		addClass(CodeId,"error");
		return false;		
	}
	Codeerror.style.display="none";
	Codeatt.style.display="none";
	Codeok.style.display="none";
	CodeId.className="U_Field";
	return true;
}
function UserInfoBut(){
	if (!userProtocol()) {
		alert("请阅读并同意DO CALL用户使用协议！");
		return false;
	}
	//是否存在
	var result = NameField();
	if (!result) {
		return false;
	}
	result = result & nameFlag;
	if (!nameFlag) {
		var errtext2="用户已注册";
		UserFieDiv.style.display="block";		
		Usererror.style.display="block";
		Useratt.style.display="none";
		Userok.style.display="none";
		Usererror.innerHTML=errtext2;
		addClass(UserId,"error");
		return false;
	}
	
	//result = result & RePassWords();
	result = result & CodeField();
	if(result == 0 || result == false){
		return false;
	}
	return true;
}
function userProtocol() {
	var box = G('U_confer');
	if (box.checked) {
		return true;
	} else {
		return false;
	}
}
function initForm() {
	if(UserId.value != ""){
		NameField();
	}
	if(EmailId.value != ""){
		EmailField();
	}
}
